import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../../../theme/font.dart';

class PassTextFieldWidget extends StatefulWidget {
  const PassTextFieldWidget({
    super.key,
    this.onChanged,
    this.onSubmit,
    this.height = 50.0,
    this.hintText = '请输入密码',
  });
  final double height;
  final String hintText;
  final Function? onChanged;
  final Function? onSubmit;
  @override
  State<PassTextFieldWidget> createState() => _PassTextFieldWidgetState();
}

class _PassTextFieldWidgetState extends State<PassTextFieldWidget> {
  TextEditingController controller = TextEditingController();
  FocusNode focusNode = FocusNode();

  bool obscureTextStatus = true;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      height: widget.height,
      margin: EdgeInsets.only(top: 8.h),
      padding: EdgeInsets.only(left: 20.w, right: 20.w),
      decoration: BoxDecoration(
          color: const Color(0xFFF4F9FB),
          borderRadius: BorderRadius.circular(24.r),
          border: Border.all(color: const Color(0xffE9E9E9), width: 0)),
      child: Row(
        children: [
          Expanded(
            child: Container(
              padding: EdgeInsets.only(bottom: 13.h),
              child: SizedBox(
                child: ConstrainedBox(
                  constraints: BoxConstraints(minHeight: 48.h),
                  child: TextField(
                    maxLength: 16,
                    focusNode: focusNode,
                    controller: controller,
                    obscureText: obscureTextStatus,
                    cursorWidth: 2,
                    cursorColor: const Color(0xFF2CC0B1),
                    // cursorHeight: 18.h,
                    autofocus: false, // 指不自动获取焦点
                    onChanged: (value) {
                      widget.onChanged?.call(value);
                      setState(() {});
                    },
                    onSubmitted: (value) {
                      widget.onSubmit?.call();
                    },
                    keyboardType: TextInputType.visiblePassword,
                    style: TextStyle(color: const Color(0xFF0C1B19), fontSize: 18.sp, fontWeight: AppFontWeight.medium),
                    decoration: InputDecoration(
                        hintText: widget.hintText,
                        counterText: '',
                        hintStyle: TextStyle(color: const Color(0xFFC2C6CC), fontSize: 15.sp),
                        border: InputBorder.none),
                  ),
                ),
              ),
            ),
          ),
          // IconButton(
          //   highlightColor: Colors.transparent,
          //   splashColor: Colors.transparent,
          //   icon: obscureTextStatus
          //       ? Image.asset(Assets.authLoginPasswordVisIcon, width: 18.5, height: 10, color: const Color(0xFF2CC0B1))
          //       : Image.asset(Assets.authLoginPasswordInvisIcon,
          //           width: 18.5, height: 10, color: const Color(0xFF2CC0B1)),
          //   onPressed: () {
          //     obscureTextStatus = !obscureTextStatus;
          //     setState(() {});
          //   },
          // )
        ],
      ),
    );
  }
}
